package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {
	private static String className = "oracle.jdbc.OracleDriver";
	private static String url = "jdbc:oracle:thin:@zha-ita114-w7:1521:wtip";
	private static String user = "jasper";
	private static String password = "123";

	//不要用单例模式，不要多线程争用connection
	public static Connection createConnection(){
		Connection con = null;
		try {
			Class.forName(className);
			con  = DriverManager.getConnection(url, user, password);//工厂方法获取连接
			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return con;
	}
	
	public static void close(Connection con, PreparedStatement pst, ResultSet rs){
		 try {
			 if(rs != null)  rs.close();
			 if(pst != null) pst.close();
			 if(con != null) con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
